package com.tms.app.tms.utils;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/11/6 0006.
 */

public class MapUtil {
    /*
 * 检查手机上是否安装了指定的软件
 *
 * @param context
 *
 * @param packageName：应用包名
 *
 * @return
 */
    public static boolean isAvilible(Context context, String packageName) {
        // 获取packagemanager
        final PackageManager packageManager = context.getPackageManager();
        // 获取所有已安装程序的包信息
        List<PackageInfo> packageInfos = packageManager.getInstalledPackages(0);
        // 用于存储所有已安装程序的包名
        List<String> packageNames = new ArrayList<String>();
        // 从pinfo中将包名字逐一取出，压入pName list中
        if (packageInfos != null) {
            for (int i = 0; i < packageInfos.size(); i++) {
                String packName = packageInfos.get(i).packageName;
                packageNames.add(packName);
            }
        }
        // 判断packageNames中是否有目标程序的包名，有TRUE，没有FALSE
        return packageNames.contains(packageName);
    }

    /*****
     * 高德地图 标注
     */
    public static void gdMarker(Context context){
        Intent  intent = new Intent("android.intent.action.VIEW",//31.192612,121.420287
                android.net.Uri.parse("androidamap://viewMap?sourceApplication=appname&poiname=湘江大厦&lat=31.192612&lon=121.420287&dev=0"));
        intent.setPackage("com.autonavi.minimap");
        context.startActivity(intent);
    }

    /*******
     * 高德地图 导航
     * @param context
     */
    public static void gdNavi(Context context){

        Intent  intent = new Intent("android.intent.action.VIEW",
                android.net.Uri.parse("androidamap://route?sourceApplication=softname&slat=30.6739968716&slon=103.9602246880&sname=当前位置&dlat=30.6798861599&dlon=103.9739656448&dname=目的地&dev=0&m=0&t=1&showType=1"));
        intent.setPackage("com.autonavi.minimap");
        context.startActivity(intent);
    }


    /*****
     * 百度地图 标注
     */
    public void dMarker(Context context){
        Intent  intent = new Intent("android.intent.action.VIEW");
        intent.setData(Uri.parse("baidumap://map/marker?location=31.192612,121.420287&title=Marker&content=makeamarker&traffic=off"));
        context.startActivity(intent);
    }


    /*****
     * 百度地图 标注
     */
    public void bdNavi(Context context){
        Intent  intent = new Intent("android.intent.action.VIEW");
        intent.setData(Uri.parse("baidumap://map/marker?location=31.192612,121.420287&title=Marker&content=makeamarker&traffic=off"));
        context.startActivity(intent);
    }


}
